#ifndef SROS_DEVICE_DETAIL_TAIHESEN_RFID_HPP
#define SROS_DEVICE_DETAIL_TAIHESEN_RFID_HPP

#include <commons/type/ret.hpp>

#include "rfid_impl.hpp"

#include <memory>
#include <atomic>

namespace sros::async
{
    class Timer;
}

namespace sros::device
{
    class McuDevice;
}

namespace sros::device::detail
{
    class TaiHeSenRfid final : public rfid_impl
    {
    public:
        TaiHeSenRfid() = default;
        TaiHeSenRfid(const uint16_t &index, std::shared_ptr<McuDevice> mcu); 
        ~TaiHeSenRfid() = default;

        // 初始化
        void init() override;

        // 运行
        void run() override;

        // 关闭
        void close() override;

        // 解析反馈报文
        void parse(const device::proto::RspUartMsg &uart_msg) override;

    private:
        void on_timer_trigger_(std::size_t times);

        RetBool send_uart_msg_(const std::vector<uint8_t> &data);

    private:
        std::shared_ptr<async::Timer> timer_;
        std::shared_ptr<McuDevice>    mcu_;
        std::atomic<uint64_t>         last_trigger_time_;  // 用来记录RFID触发的时间戳
        std::atomic<uint64_t>         last_recv_time_;     // 用来检测是否通讯失联的时间戳
        std::atomic<bool>             is_rfid_on_;         // RFID是否触发
        std::atomic<bool>             last_conn_state_;    // 记录上一次的连接状态
    };
}

#endif